import { useUserStore } from '@/store';

function setupAuthorization(config) {
  const { token } = useUserStore();

  if (token?.accessToken) {
    config.headers.Authorization = token?.accessToken;
  }

  return config;
}

export const setupRequestInterceptor = (http) => {
  http.interceptors.request.use(
    function (config) {
      return setupAuthorization(config);
    },
    function (error) {
      return Promise.reject(error);
    }
  );
};
